import * as actions from '../actions/index';

// 对页面prop 数据进行管理
export const initialState = {
  tableData: [],
  currentPage: 1,
  pageSize: 10,
  total: 0,
  isLoadingTable: true,
  // 是否已经获取到表格数量
  tableDataFetched: false,
};
const defaultAction = {
  type: 'doNothing',
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    case actions.RECEIVE_TRASHES_DATA: {
      const total = action.data.shift().amount;
      return {
        ...state,
        tableData: action.data,
        total,
        currentPage: action.data.currentPage,
        tableDataFetched: true,
      };
    }
    case actions.RESET_DATA:
      return { ...initialState };
    default:
      return state;
  }
}
